package com.wipz.eoa.iphone.officesupplies;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.toft.widgets.workflow.model.CompleteTaskResult;
import com.toft.widgets.workflow.utils.ConstantUtil;
import com.wipz.eoa.iphone.businessProcess.BusinessCoreServices;

public class OfficeSuppliesBackApplyServiceImpl extends BusinessCoreServices implements
		IOfficeSuppliesBackApplyService {

	@Override
	public Map bxSubmit(Map param)  {
		String COMMITERCODE = (String) param.get("COMMITERCODE");
		//获取ID
		String id = (String) param.get("ID"); 
		//任务唯一标识taskId
		String taskId = (String) param.get("taskId");
		//处理意见
		String commentContent = (String) param.get("commentContent");
		//流向
		String transition = (String) param.get("transition");
		//处理类型
		String typeaccept = (String) param.get("typeaccept");
		
		String PROCESSID = (String) param.get("PROCESSID");
		
		String uuitId = (String) param.get("UuitId");
		
		String SUPLIESCODE = (String)param.get("SUPLIESCODE");
		
		boolean pass = "true".equals(typeaccept) ? true:false;
		Map variable = new HashMap(); 
		variable.put(ConstantUtil.TASK_COMMNET_TYPE, ConstantUtil.APPROVE_OPERATION_PASS.equals(typeaccept) ? ConstantUtil.TASK_COMMNET_TYPE_ACCEPT : ConstantUtil.TASK_COMMNET_TYPE_REFUSE); // 意见类型
		variable.put(ConstantUtil.TASK_COMMENT_CONTENT, commentContent); // 意见内容
		variable.put(ConstantUtil.AGENCY_ID,uuitId );
		CompleteTaskResult result = this.complete(COMMITERCODE, taskId, transition, variable, pass,uuitId);
		if(result == null) {
			return null;
		}
		String nextOne = result.getNextOperators();
		Map map = new HashMap();
		//流程是否结束
		if(result.isEnded()){
			String operationFlag = "officesuppliesBackApply.updateProcessStatus";
			super.updateWorkflowProcessStatus("END",operationFlag,id,"",PROCESSID);
			//this.getContext().dataResult.setMessage("true");
			//归还流程完成，修改办公用品归还状态为:3归还成功
			Map statusMap = new HashMap();
			statusMap.put("SUPLIESCODE", SUPLIESCODE);
			statusMap.put("ISBACKAPPLY", "3");
			super.update("myofficesupplies.updateWhenBackApplyByCode", statusMap);
			map.put("NEXTAPPROVALER", "审批结束");
			map.put("ID", id);
			super.update("officesuppliesBackApply.updateNextapprovaler", map);
		}else{
			if (pass){
				map.put("NEXTAPPROVALER", nextOne);
				map.put("ID", id);
				super.update("officesuppliesBackApply.updateNextapprovaler", map);
			}else{
				String operationFlag = "officesuppliesBackApply.updateProcessStatus";
				super.updateWorkflowProcessStatus("BACK",operationFlag,id,nextOne,PROCESSID);
				//归还流程被打回，修改办公用品归还状态为:0未归还
				Map statusMap = new HashMap();
				statusMap.put("SUPLIESCODE", SUPLIESCODE);
				statusMap.put("ISBACKAPPLY", "1");
				super.update("myofficesupplies.updateWhenBackApplyByCode", statusMap);
			}
		}
	//	this.getContext().addAttribute("result", result);
		Map resultMap = new HashMap();
		resultMap.put("ended", result.isEnded()+"");
		resultMap.put("back", result.isBack()+"");
		resultMap.put("nextOperators",result.getNextOperators());
		return resultMap;
	}

	@Override
	public List queryList(String str, Map map) {
		return  super.queryList(
				"officesuppliesBackApply.querylist", map);
	}

	


}
